#ifndef __TROPHY_UNIT_TEST_H__
#define __TROPHY_UNIT_TEST_H__

#include <stdlib.h>
#include <stdio.h>


#define TEST_ASSERT(e) \
   do { \
      if (!(e)) { \
         printf("******Test failed!, '%s' is not satisfied, file %s, line %d\n", #e, __FILE__, __LINE__); \
         g_test.m_pass = false; \
      }  \
   } while (0) 

class CTestGroup;

typedef struct s_TestCaseNode {
   struct s_TestCaseNode* next;
   const char* CaseName;
   CTestGroup* Testcase;
} TestCaseNode;


class CUnitTest
{
public:
   CUnitTest();
   virtual ~CUnitTest();
   
public:
   int AddCase(const char* name, CTestGroup* test);
   int RunAll();

   bool m_pass;

protected:
   int m_caseCount;
   TestCaseNode* m_caseList;
   TestCaseNode* m_tail;
};

extern  CUnitTest g_test; 

class CTestGroup
{
public:
    virtual void Setup() {};
    virtual void TearDown() {};
    virtual void TestFunc() {};
};

#define TEST_GROUP(grp)  struct CTestGroup_##grp : public CTestGroup

#define TEST_CASE(grp,func) \
   ; \
   class CTESTCASE_##func : public CTestGroup_##grp  \
   {  \
   public: \
      CTESTCASE_##func() \
      {  \
         g_test.AddCase(#func, this);\
      }  \
      virtual void TestFunc(); \
   };  \
   CTESTCASE_##func class_##func; \
void  CTESTCASE_##func::TestFunc()

#endif //__TROPHY_UNIT_TEST_H__
